﻿using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using System.Threading;
using HisoftSmart.Client.AutomationClient.UIAutomationServiceReference;
using HisoftSmart.Client.AutomationClient.Helpers;

namespace HisoftSmart.Client.AutomationClient.Actions
{
    public class SetFocusAction : ActionBase
    {
        public SetFocusAction(string name, string _params)
            : base(name, _params)
        {
            AutomationIdentifier = new AutomationIdentifier(this.Params.Split(',')[0], AutomationIdentification.TryDisplayedText);
        }

        protected override void DoImpl()
        {
            var element = GetFrameworkElement();
            if (element == null)
                return;

            var control = element as Control;
            if (control == null)
            {
                SendNotFoundResult();
                return;
            }

            control.Focus();
            SendSuccessResult();
        }
    }
}
